#include "virus.h"
#include "utils.h"
#include <stdlib.h>

Virus::Virus(int infect, int vir, int immuneres, int drugres, QObject *parent)
    : QObject(parent)
{
    Infectivity = infect;
    ImmuneResistance = immuneres;
    Virulence = vir;
    HP = 1000;

    DrugResistance = drugres;
    Mutate();
}

Virus::Virus(Virus *parentVirus, QObject *parent)
    : QObject(parent)
{
    Infectivity = parentVirus->Infectivity;
    ImmuneResistance = parentVirus->ImmuneResistance;
    Virulence = parentVirus->Virulence;
    HP = 1000;

    DrugResistance = parentVirus->DrugResistance;
    Mutate();
}

void Virus::Mutate()
{
    //Mutate the thing!
    int mutatechance = 60;

    if(rand() % 100 < mutatechance)
    {
        Infectivity += (rand() % 11) - 5;
    }
    if (rand() % 100 < mutatechance)
    {
        Virulence += (rand() % 100) - 50;
    }
    if(rand() % 100 < mutatechance)
    {
        ImmuneResistance += (rand() % 100) - 50;
    }
    if(rand() % 100 < mutatechance)
    {
        DrugResistance += (rand() % 100) - (rand() % 100);
    }

    Infectivity = Utils::clamp(Infectivity, 0, 1000);
    DrugResistance = Utils::clamp(DrugResistance, 0, 1000);
    Virulence = Utils::clamp(Virulence, 0, 1000);
    ImmuneResistance = Utils::clamp(ImmuneResistance, 0, 1000);
}

void Virus::setHP(double value)
{
    HP = Utils::clamp(value, 0.0, 1000.0);
}

double Virus::getHP()
{
    return HP;
}

